new Vue({
    el: "#wap_work",
    data() {
        return {
            services: services,
            currJob:'',
            currWorkCom:'',
            currWorkStartTime:'',
            currWorkEndTime:'',
            currWorkDepart:'',
            currWorkPosition:'',
            currWorkDuty:'',
            currResumeId:'',
            currId:'',
            currIndex:'',
        }
    },
    created () {
        this.currResumeId = $.cookie('resumeId');
        this.currId = GetQueryString('id');
        this.currIndex= GetQueryString('index');
        var storage=window.localStorage;
        this.currJob = JSON.parse(storage.jobs);
        this.currWorkCom = this.currJob[this.currIndex].company;
        this.currWorkStartTime = this.currJob[this.currIndex].entryTime;
        this.currWorkEndTime = this.currJob[this.currIndex].separationTime;
        this.currWorkDepart = this.currJob[this.currIndex].department;
        this.currWorkPosition = this.currJob[this.currIndex].position;
        this.currWorkDuty = this.currJob[this.currIndex].workContext;
    },
    methods:{
        saveWork:function () {
            this.currWorkStartTime = $('input[name="alter_start"]').val();
            this.currWorkEndTime = $('input[name="alter_end"]').val();
            if(this.currWorkCom==''||this.currWorkCom==null){
                layerMsg("公司名字不可以为空");
                return
            }
            if(this.currWorkStartTime == ''||this.currWorkStartTime==null){
                layerMsg('开始工作时间不为空');
                return
            }
            if(this.currWorkEndTime == ''||this.currWorkEndTime==null){
                layerMsg('结束工作时间不为空');
                return
            }
            var that = this;
            $.ajax({
                url:that.services+"/user/resume/experienceWork"
                ,type:"post"
                ,contentType:"application/json;charset=utf-8"
                ,xhrFields: {
                    withCredentials: true
                }
                ,crossDomain: true
                ,data:JSON.stringify({
                    "id": that.currId
                    ,"resumeId": that.currResumeId
                    ,"company": that.currWorkCom
                    ,"department": that.currWorkDepart
                    ,"position": that.currWorkPosition
                    ,"entryTime": that.currWorkStartTime
                    ,"separationTime": that.currWorkEndTime
                    ,"workContext": that.currWorkDuty
                })
                ,success:function(res){
                    console.log(res);
                    if(res.success){
                        var check = ApiLoginStatus(res);
                        if(check==false)
                            return false;
                        layerMsg(res.message);
                        setTimeout(function() {
                            window.location.href="my-resume.html" ;
                        },500);
                    }
                }
            });
        },
        deleteWork:function () {
            var that = this;
            layer.confirm('删除后无法恢复，确认要删除吗', {title:false,closeBtn:0,scrollbar: false}, function(index){
                $.ajax({
                    url:that.services+"/user/resume/experienceWork/"+that.currId
                    ,type:"delete"
                    ,contentType:"application/json;charset=utf-8"
                    ,xhrFields: {
                        withCredentials: true
                    }
                    ,crossDomain: true
                    ,success:function(res){
                        console.log(res);
                        if(res.success){
                            var check = ApiLoginStatus(res);
                            if(check==false)
                                return false;
                            layerMsg(res.message);
                            setTimeout(function() {
                                window.location.href="my-resume.html" ;
                            },500);
                        }
                    }
                });
                layer.close(index);
            });
        }
    }
});